﻿using System.Collections;
using UnityEngine;

    public static class CollisionExtension
{
    public static Vector2 GetForce(this Collision2D collision)
    {
        Vector2 Force = Vector2.zero;

        foreach (ContactPoint2D point in collision.contacts)
        {
            Force += point.normal * point.normalImpulse / Time.fixedDeltaTime;
            //     impulse += point.normalImpulse;
        }

        return Force;
    }
    public static Vector2 GetContactPos(this Collision2D collision)
    {
        Vector2 pos = Vector2.zero;
        float sum = 0;
        foreach (ContactPoint2D point in collision.contacts)
        {
            pos += point.point*point.normalImpulse;
            sum += point.normalImpulse;
        }
        return pos / sum;
    }
}
